// 注：这个文件被用于管理项目中所有与“SKU管理模块”有关的接口
import request from '@/utils/request'
import type {
    typeOfResponseDataOfTheApiThatGetSkuList,
    typeOfResponseDataOfTheApiThatGetSkuDetailInformation,
} from '@/api/product/sku/type'
// 枚举接口地址↓
enum API {
    // 获取某个SPU下的已有商品（即“SKU”）列表时需要用到的接口地址↓
    getSkuList_URL = '/admin/product/list/',
    // 上架商品时需要用到的接口地址↓
    makeAnSkuForSale_URL = '/admin/product/onSale/',
    // 下架商品时需要用到的接口地址↓
    makeAnSkuNotForSale_URL = '/admin/product/cancelSale/',
    // 获取某个SKU的详细信息时需要用到的接口地址↓
    getTheDetailInformationOfAnSku_URL = '/admin/product/getSkuInfo/',
    // 删除某个SKU时需要用到的接口地址↓
    deleteAnSku_URL = '/admin/product/deleteSku/',
}
// 向获取SKU列表的接口发送请求时需要用到的方法↓
export const requestSkuList = async(currentPageNumber: number, currentPageSize: number) => {
    try {
        let response = await request.get<any, typeOfResponseDataOfTheApiThatGetSkuList>(API.getSkuList_URL + `${currentPageNumber}/${currentPageSize}`)
        console.log(response)
        return response
    } catch (error) {
        console.error('获取SKU列表失败', error)
    }
}
// 上架商品时需要用到的方法↓
export const requestMakeAnSkuForSale = async (skuId: number) => {
    try {
        let response = await request.get<any, any>(API.makeAnSkuForSale_URL + skuId)
        console.log(response)
        return response
    } catch (error) {
        console.error('上架商品失败', error)
    }
}
// 下架商品时需要用到的方法↓
export const requestMakeAnSkuNotForSale = async (skuId: number) => {
    try {
        let response = await request.get<any, any>(API.makeAnSkuNotForSale_URL + skuId)
        console.log(response)
        return response
    } catch (error) {
        console.error('下架商品失败', error)
    }
}
/**
 * @description 获取某个SKU的详细信息时需要用到的方法
 * @param skuId SKU的ID号
 * @returns 一个promise对象，该promise对象在被resolve时将会返回一个包含SKU详细信息的对象
 */
export const requestGetTheDtailInformationOfAnSku = async (skuId: number) => {
    try {
        let response = await request.get<any, typeOfResponseDataOfTheApiThatGetSkuDetailInformation>(API.getTheDetailInformationOfAnSku_URL + skuId)
        console.log(response)
        return response
    } catch (error) {
        console.error('获取SKU的详细信息失败', error)
    }
}
export const requestDeleteAnSku = async (skuId: number) => {
    try {
        let response = await request.delete<any, any>(API.deleteAnSku_URL + skuId)
        console.log(response)
        return response
    } catch (error) {
        console.error('删除SKU失败', error)
    }
}